﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto.Middle.Request.Customs;
using BenCaoXuan.Infrastructure.Dto;
using BenCaoXuan.Service.Interface.middle;
using Microsoft.AspNetCore.Mvc;
using BenCaoXuan.Infrastructure.Dto.Middle.Request.Register;
using BenCaoXuan.Infrastructure.Dto.Middle.Request.Commission;
using BenCaoXuan.Infrastructure.Dto.Middle.Response.Customs;

namespace BenCaoXuan.Api.Admin.Controllers.middle
{
    [ApiGroup("Middle(移动端模块)")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PromoteController : ControllerBase
    {
        private readonly I_Promote_Service _promote_Service;

        public PromoteController(I_Promote_Service promote_Service) {
            _promote_Service = promote_Service;
        }
        /// <summary>
        /// 获取消费统计数据（按日、周、月分组）
        /// </summary>
        [HttpGet]
        public async Task<IActionResult> Get_ConsumeStats(string customerId, string dateRange)
        {
            var result = await _promote_Service.Get_ConsumeStats(customerId, dateRange);
            return Ok(result);
        }
        /// <summary>
        /// 获取消费
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<IActionResult> Get_CustomerConsumeStats(string customerId)
        {
            var result = await _promote_Service.Get_CustomerConsumeStats(customerId);
            return Ok(result);
        }
        /// <summary>
        /// 检查推广人的所有被推广人订单，仅≤5条时处理佣金（含积分）
        /// </summary>
        /// <param name="customerId">推广人ID（当前登录客户ID）</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Check_InviteeCommission([FromQuery] string customerId)
        {
            var result = await _promote_Service.Check_InviteeCommission(customerId);
            return Ok(result);
        }
        /// <summary>
        /// 获取该客户的消费、积金、佣金
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_CustomerFinance(string customerId)
        {
            var result = await _promote_Service.Get_CustomerFinance(customerId);
            return Ok(result);
        }
        /// <summary>
        /// 获取佣金排名前五的客户
        /// </summary>
        /// <returns>包含客户佣金及VIP信息的列表</returns>
        [HttpGet]
        public async Task<IActionResult> Get_Top_FiveCommission()
        {
            var result = await _promote_Service.Get_Top_FiveCommission();
            return Ok(result);
        }
        /// <summary>
        /// 客户注册
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Register(Customs_Request_Dto dto)
        {
            var result = await _promote_Service.Register(dto);
            return Ok(result);
        }
        /// <summary>
        /// 新增佣金
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_CustomerCommission(Commission_Request_Dto dto)
        {
            var result = await _promote_Service.Add_CustomerCommission(dto);
            return Ok(result);
        }
        ///// <summary>
        ///// 新增佣金
        ///// </summary>
        ///// <param name="registerId"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<IActionResult> Add_CustomerCommission(string registerId)
        //{
        //    var result = await _promote_Service.Add_CustomerCommission(registerId);
        //    return Ok(result);
        //}
        /// <summary>
        /// 新增VIP客户并更新客户表为正式客户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_VipCustomer(VipCustomer_Request_Dto dto)
        {
            var result = await _promote_Service.Add_VipCustomer(dto);
            return Ok(result);
        }
        /// <summary>
        /// 检查客户是否为VIP
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> CheckIsVip(string customerId)
        {
            var result = await _promote_Service.CheckIsVip(customerId);
            return Ok(result);
        }

        /// <summary>
        /// 给推广人添加推广成功的注册佣金数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddCustomerCommissionByRegister(AddCustomerCommissionByRegister_Dto dto) {
            var result = await _promote_Service.AddCustomerCommissionByRegister(dto);
            return Ok(result);
        }
    }
}
